package cn.sjxy.regi.service.impl;

import cn.sjxy.regi.mapper.EmployeeMapper;
import cn.sjxy.regi.pojo.Employee;
import cn.sjxy.regi.service.EmployeeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

/**
 * ClassName:EmployeeServiceImpl
 * Package:cn.sjxy.service.impl
 * Description:
 *
 * @Date:2022/5/23 18:37
 * @Author:SXW
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {

    @Override
    public Page getPage(int page, int pageSize, String name) {
        // 分页构造器
        Page pageInfo = new Page(page, pageSize);
        // 条件构造器
        LambdaQueryWrapper<Employee> wrapper = new LambdaQueryWrapper();
        // 添加条件查询，先判断 name 是否为空，为空则不添加条件
        wrapper.like(StringUtils.isNotEmpty(name), Employee::getName, name);
        // 添加排序条件
        wrapper.orderByDesc(Employee::getUpdateTime);
        // 执行查询
        this.page(pageInfo, wrapper);
        return pageInfo;
    }
}
